Program operational metrics
Program-wide operational metrics.
Reads counters that live directly on the bound program object:
specifically {phase}_cumulated_invocations and
{phase}_cumulated_invocation_elapsed_s, which
Module._maybe_reset_call_context bumps whenever the program is the
entry module of a top-level call. That gives true wall-clock elapsed
and invocation counts at the program boundary, not a sum of nested
LM/EM per-call times.
For cost, which is paid by individual providers and tracked on each
LanguageModel / EmbeddingModel, the base class also collects the LM
and EM trees reachable from the program (including .fallback chains)
so subclasses can sum across them.
ProgramAvgCostPerInvocation
Bases: ProgramOperationalMetric
USD per program call, inference only; use for unit cost, not totals.
Average provider cost per program invocation: the cost of the program's own calls (inference), without its judge's or optimizer's.
Example:
Source code in synalinks/src/metrics/program_metrics.py
ProgramCalls
Bases: ProgramOperationalMetric
Top-level program invocations; use to normalize other counters per call.
One increment per call to program(...), regardless of how many LM
or EM calls the program makes internally.
Example:
Source code in synalinks/src/metrics/program_metrics.py
ProgramCallsPerSecond
Bases: ProgramOperationalMetric
Program calls per wall-clock second; use for serving throughput.
Example:
Source code in synalinks/src/metrics/program_metrics.py
ProgramCost
Bases: ProgramOperationalMetric
USD over every bound LM/EM in all phases; use for total spend, not per call.
Total provider cost (USD, as reported by litellm) across every LM and EM reached from the program for this run, in every phase: the program's own calls, its judge's (reward) and its optimizer's. The program object itself doesn't pay providers; cost is summed from its bound models.
Example:
Source code in synalinks/src/metrics/program_metrics.py
ProgramElapsedTime
Bases: ProgramOperationalMetric
Summed wall-clock seconds inside program calls; use for end-to-end time.
End-to-end wall-clock seconds spent inside program(...) during
this run. Sums per-invocation wall-clock; does not double-count
nested LM/EM calls.
Example:
Source code in synalinks/src/metrics/program_metrics.py
ProgramOperationalMetric
Bases: Metric
Program-wide counter metric base; subclass to add one, don't compile it.
Subclasses set _phase to one of "inference", "reward", or
"optimizer" to read the corresponding counter set. Counters are
populated based on the active op_scope (contextvar) the trainer
sets for each phase.
Example:
Source code in synalinks/src/metrics/program_metrics.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |